Repository navigation
Add JSON output, typed exit codes and a .valar.yml schema - #21
Merged
Merged
Conversation
--json, or VALAR_OUTPUT=json, makes every command print its result as one
JSON document on stdout, logs as one JSON object per line, and errors as
{"error": {"kind", "message"}} on stderr. Human output is unchanged.
Exit codes now tell failures apart: 1 failed, 2 invalid arguments or
configuration, 3 not found, 4 not allowed, 5 conflict, 6 unavailable.
They are listed in 'valar help' and the README.
'valar config schema' prints the JSON Schema of .valar.yml, generated from
the config types and checked in at schema/valar.yml.json; a test keeps the
two in step. Loading .valar.yml refuses unknown keys, naming the key, its
line and the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Machine-readable output
--json, orVALAR_OUTPUT=json, makes every command print its result as one JSON document on stdout:[]when empty);build inspect,batch inspect,deployment create/rollback,project create,whoami, ...); commands without a result body print a small object naming what changed ({"domain": "...", "deleted": true});service logs,build logs,build watchandbatch logsprint one JSON object per line: build log entries as{"timestamp", "source", "stage", "content"}, service and batch output as{"content"};push --waitbuild log, prompts,batch run --followoutput) goes to stderr;{"error": {"kind": "notFound", "message": "..."}}, including cobra's argument and flag errors.build push --jsonprints the submitted build right away, so its ID is known even when--waitthen fails.Human output is unchanged.
Exit codes
failedinvalidnotFoundnotAllowedconflictservice initover an existing fileunavailableUntyped errors keep exit code 1. Cobra usage errors and missing settings (
Operation requires ...) now exit with 2.build statuskeeps exiting 1 for any build that is not done, and now reports API errors instead of exiting 0. The table is invalar helpand the README..valar.ymlschemavalar config schemaprints a JSON Schema generated from the config types; it is checked in atschema/valar.yml.jsonandTestSchema_MatchesCheckedInFilefails when they drift (go test ./config -run TestSchema -updateregenerates it). Loading.valar.ymlnow refuses unknown keys, for example:The deprecated
environmentlists stay valid and keep their push warning.Tests
Table-driven tests for the status-to-exit-code mapping, JSON error output,
--json/VALAR_OUTPUTdetection, JSON line streaming, JSON output of list and inspect commands, and schema validation.